from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

import core
from core.models import User


class AuthProvider(models.Model):
    name = models.CharField(max_length=255, unique=True)

    class Meta:
        app_label = core.APP_LABEL

    def __unicode__(self):
        return self.name


class Auth(models.Model):
    provider = models.ForeignKey(AuthProvider)
    credential = generic.GenericForeignKey('content_type', 'credential_id')

    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType)
    credential_id = models.PositiveIntegerField()

    class Meta:
        app_label = core.APP_LABEL

    def __unicode__(self):
        return '{0} {1}'.format(self.provider, self.credential)